<?php
/*日志*/
header("Content-type:text/html;charset=utf-8");
date_default_timezone_set('PRC');
/*日志写入接口*/
function write_log($arr=array(),$type='all')
{
	$arr = array_merge($_REQUEST,$arr);
	/*当前时间*/
	$now = date('Y-m-d H:i:s');
	/*日志文件路径*/
	$destination = dirname(__FILE__).'/../log/'.$type.'/'.date('Ym').'/'. date('d') . '.log';
	$path = dirname($destination);
    !is_dir($path) && mkdir($path, 0755, true);
    //检测日志文件大小，超过配置大小则备份日志文件重新生成
    if (is_file($destination) && floor(2097152) <= filesize($destination)) 
    {
        rename($destination, dirname($destination) .'/'. $_SERVER['REQUEST_TIME'] . '-' . basename($destination));
    }
    $arr['timestamp'] = $_SERVER['REQUEST_TIME'];
    $arr['server_addr'] = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '0.0.0.0';
    $arr['remote_addr'] = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0';
    $arr['method'] = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'CLI';
    $arr['url'] = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
    $str = var_export($arr,true);
    error_log('['.$now."]\r\n".$str."\r\n---------------------------------------------------------------\r\n",3,$destination);
}
